package nf.graph.persistence;

/**
 * Thrown on parse errors.
 */
public class ParseException extends RuntimeException
{
	private int lineNumber;

	public ParseException()
	{
		this(null);
	}
	
	public ParseException(String message)
	{
		this(message, 0);
	}
	
	public ParseException(String message, int lineNumber)
	{
		this(message, lineNumber, null);
	}
	
	public ParseException(String message, int lineNumber, Throwable cause)
	{
		super(message, cause);
		this.lineNumber = lineNumber;
	}

	/**
	 * Returns the line number at which the parse error occurred
	 * @return Line number at which the parse error occurred
	 */
	public int getLineNumber()
	{
	    return lineNumber;
	}

	public String toString()
	{
		if (lineNumber == 0)
			return super.toString();

		return String.format("%s on line %d: %s", getClass().getName(),
			lineNumber, getLocalizedMessage());
	}
}
